//
//  CAOrderDetailGoodsTableViewCell.m
//  LNH
//
//  Created by twentylx on 2018/2/23.
//  Copyright © 2018年 twentylx. All rights reserved.
//

#import "CAOrderDetailGoodsTableViewCell.h"

@implementation CAOrderDetailGoodsTableViewCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addSubview:self.goodsBackgroundView];
        [self addSubview:self.goodsImageView];
        [self addSubview:self.goodsNameLabel];
        [self addSubview:self.brandLabel];
        [self addSubview:self.priceLabel];
        [self addSubview:self.returnButton];
        [self addSubview:self.lineView];
        
        [_goodsBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        
        [_goodsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsBackgroundView).offset(10);
            make.top.equalTo(self.goodsBackgroundView).offset(10);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(100);
        }];
        
        [_goodsNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsImageView.mas_right).offset(10);
            make.top.equalTo(self.goodsImageView).offset(5);
            make.right.equalTo(self).offset(-80);
        }];
        
        [_brandLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsNameLabel);
            make.top.equalTo(self.goodsNameLabel.mas_bottom).offset(10);
            make.right.equalTo(self).offset(-80);
        }];
        
        [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.goodsNameLabel);
            make.top.equalTo(self.brandLabel.mas_bottom).offset(10);
        }];
        
        [_returnButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.goodsBackgroundView).offset(-20);
            make.bottom.equalTo(self.goodsImageView);
            make.width.mas_equalTo(60);
            make.height.mas_equalTo(30);
        }];
        
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.and.right.equalTo(self.goodsBackgroundView);
            make.bottom.equalTo(self.goodsBackgroundView);
            make.height.mas_equalTo(ONE_PIXEL);
        }];
    }
    return self;
}

#pragma mark get & set
- (UIView *)goodsBackgroundView {
    if (!_goodsBackgroundView) {
        _goodsBackgroundView = [[UIView alloc] init];
        _goodsBackgroundView.backgroundColor = [UIColor whiteColor];
    }
    return _goodsBackgroundView;
}

- (UIImageView *)goodsImageView {
    if (!_goodsImageView) {
        _goodsImageView = [UIImageView new];
        _goodsImageView.layer.borderWidth = 1;
    }
    return _goodsImageView;
}

- (UILabel *)goodsNameLabel {
    if (!_goodsNameLabel) {
        _goodsNameLabel = [UILabel new];
        _goodsNameLabel.numberOfLines = 3;
        _goodsNameLabel.lineBreakMode = NSLineBreakByCharWrapping;
        _goodsNameLabel.font = [UIFont systemFontOfSize:16];
    }
    return _goodsNameLabel;
}

- (UILabel *)brandLabel {
    if (!_brandLabel) {
        _brandLabel = [UILabel new];
        _brandLabel.textColor = RGBCOLOR(116, 116, 116);
        _brandLabel.font = [UIFont systemFontOfSize:14];
        _brandLabel.numberOfLines = 2;
        _brandLabel.lineBreakMode = NSLineBreakByCharWrapping;
    }
    return _brandLabel;
}

- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = [UILabel new];
        _priceLabel.textColor = RGBCOLOR(233, 85, 19);
        _priceLabel.font = [UIFont systemFontOfSize:14];
        _priceLabel.textAlignment = NSTextAlignmentRight;
    }
    return _priceLabel;
}

- (UIButton *)returnButton {
    if (!_returnButton) {
        _returnButton = [UIButton new];
        [_returnButton setTitle:@"售后" forState:UIControlStateNormal];
        [_returnButton setTitleColor:RGBCOLOR(62, 62, 62) forState:UIControlStateNormal];
        _returnButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _returnButton.layer.borderWidth = 1;
        _returnButton.layer.borderColor = [RGBCOLOR(157, 157, 157) CGColor];
        _returnButton.layer.cornerRadius = 5;
    }
    return _returnButton;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = RGBCOLOR(224, 224, 224);
    }
    return _lineView;
}

#pragma mark func
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
